package com.yuxi.Test;


import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;

import com.yuxi.Config.ConfigStatic;
import com.yuxi.Dao.IExcelDao;
import com.yuxi.Dao.InformationDao;
import com.yuxi.Dao.InformationPortDao;
import com.yuxi.Dao.InformationSortDao;
import com.yuxi.Dao.PositionDao;
import com.yuxi.Dao.PrisonStructureDao;
import com.yuxi.Dao.TaskDispatchDao;
import com.yuxi.Dao.UserInfoDao;
import com.yuxi.Dao.Impl.InformationDaoImpl;
import com.yuxi.Entity.Information;
import com.yuxi.Entity.InformationPort;
import com.yuxi.Entity.Position;
import com.yuxi.Entity.PrisonStructure;
import com.yuxi.Entity.TaskDispatch;
import com.yuxi.Entity.UserInfo;
import com.yuxi.Request.InformationQuery;
import com.yuxi.Service.UserInformationService;
import com.yuxi.Service.UserService;
import com.yuxi.Service.Impl.UserServiceImpl;
import com.yuxi.Util.ExportExcel;
import com.yuxi.Util.PoiExcelExport;




@RunWith(BlockJUnit4ClassRunner.class)
public class test extends UnitTestBase {
	public test() {
		super("classpath*:applicationContext.xml");
	}
	
	@Test
	public void test1(){
		 // 测试学生  
        ExportExcel<TaskDispatch> ex = new ExportExcel<TaskDispatch>();  
        String[] headers =  
        { "安全信息内容", "信息分级", "信息分类", "处置标准及措施", "派遣人","派遣时间","完成时限","完成情况","责任人","派遣 备注"};  
        List<TaskDispatch> dataset = new ArrayList<TaskDispatch>(); 
        TaskDispatchDao task=super.getBean(TaskDispatchDao.class);
        dataset=task.getAll();
        System.out.println(dataset.toString());
        try  
        {  
            OutputStream out = new FileOutputStream("E://a.xls");           
           // ex.exportExcel("任务派遣单",headers, dataset, out,"yyyy-MM-dd");          
            out.close();
            System.out.println("excel导出成功！");  
        } catch (FileNotFoundException e) {  
            e.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
	 
	}
	
	@Test
	public void test2(){
		
		PoiExcelExport pee = new PoiExcelExport("E:/test3.xls","222");
		//数据
		 List<TaskDispatch> dataset = new ArrayList<TaskDispatch>(); 
	        TaskDispatchDao task=super.getBean(TaskDispatchDao.class);
	        dataset=task.getAll();       
        //调用
        String titleColumn[] = {"informationId","perSonLiableName","personDispatchName","createTime","taskTime"};
        String titleName[] = {"信息ID","责任人","派遣人","派遣时间","任务时间"};
        int titleSize[] = {15,15,15,15,15};
//        //其他设置 set方法可全不调用
//        String colFormula[] = new String[5];
//        colFormula[4] = "D@*12";   //设置第5列的公式
//        pee.setColFormula(colFormula);
//        pee.setAddress("A:D");  //自动筛选 
        pee.setTitleFontSize((short)14);  
        pee.setTitleBackColor("CCE8CF");
     //   pee.setContentFontSize((short)30);
        pee.wirteExcel(titleColumn, titleName, titleSize, dataset);
	}
	
	@Test
	public void testDao(){
		InformationSortDao i=super.getBean(InformationSortDao.class);
		System.out.println(i.hashCode());		
		System.out.println(ConfigStatic.getIfSort().toString());
		
	}
	
	@Test
	public void testDao12(){
		UserInfoDao idao=super.getBean(UserInfoDao.class);
		UserService i=super.getBean(UserService.class);
		UserInfo u=idao.getUser(1);
		System.out.println(i.getUserPowerViewByUserId(u).toString());
		
	}
	
	@Test
	public void testDao13(){
		UserService idao=super.getBean(UserService.class);	
		System.out.println("1"+idao.getUserPrisonArea(1));
		
		System.out.println("3"+idao.getUserPrisonArea(3));
		
		System.out.println("4"+idao.getUserPrisonArea(4));
		
		System.out.println("8"+idao.getUserPrisonArea(8));		
		System.out.println("10"+idao.getUserPrisonArea(10));
		
		System.out.println("11"+idao.getUserPrisonArea(11));
		
		System.out.println("13"+idao.getUserPrisonArea(13));
	}
	
	@Test
	public void testDao14(){
		IExcelDao idao=super.getBean(IExcelDao.class);	
//		System.out.println(idao.outWordForInformationByIdArray(new String[]{"99"}));
	
	}
	@Test
	public void testPort(){
		String portStr="1,2";
		InformationPortDao portDao =super.getBean(InformationPortDao.class);
		List<InformationPort> ports = portDao.getAllInfoPort();
		String[] portId=portStr.split(",");
		portStr=portStr+",";
		for (int i = 0; i < portId.length; i++) {
			portStr=portStr+getAllChildPort(Integer.parseInt(portId[i]),ports);
//			InformationPortPower informationPortPower =new InformationPortPower();
//			informationPortPower.setRoleId(roleId);
//			informationPortPower.setPortId(Integer.parseInt(portId[i]));
//			informationPortPowerDao.addPortPower(informationPortPower);
		}
		
	}
	private String getAllChildPort(int  portId,List<InformationPort> ports){
		String childPort="";
		for(InformationPort port :ports){
			if (port.getSuperId()==portId) {
				childPort+=Integer.toString(port.getId())+",";
				childPort=childPort+ getAllChildPort(port.getId(),ports);
			}
			
		}
		return childPort;
	}
	@Test
	public void adddinfor(){
		InformationDao in=super.getBean(InformationDao.class);
		Information oni=in.getInformationById(102);
		oni.setId(0);
		Information x=in.addInformation(oni);
		System.out.println(x);
	}
	
	@Test
	public void deleteInfo(){
//		InformationDao in=super.getBean(InformationDao.class);
//		in.deleteInformationBYId(102);
		
		IExcelDao in=super.getBean(IExcelDao.class);
		in.deleteOwnById(52);
	}
}
